import React, { useState } from 'react'
import { View, Text, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import './index.less'


export default function Iconcard(props) {
 let [islogin,setLogin] = useState(false)
 let [avurl,setAvurl] = useState('')
 let [nickName,setnickName] = useState('')
  let handleLogin = ()=>{
    Taro.login({
      success: function (res) {
        if (res.code) {
          console.log(res)
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
    Taro.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      setLogin(true)
       setAvurl(res.userInfo.avatarUrl)
       setnickName(res.userInfo.nickName)
       console.log(res)
      }
    })
  }
  return (
    <View className='idcard_box'>
     { islogin&&<View>
        <View className='box_top'>
          <View className='mine_img' style={{backgroundImage:'url('+avurl+')'}}></View>
          <View className='mine_info'>
            <View className='username'>{nickName||'微信用户'}</View>
            <View className='span'>这个人很懒啥也没有写</View>
          </View>
        </View>
        <View className='mine_tag'>
          <View className='one_tag'>
            收藏 1
          </View>
          <View className='one_tag middle'>投稿 1</View>
          <View className='one_tag'>粉丝 2</View>
        </View>
      </View>}
      {
        !islogin&&<View onClick={()=>handleLogin()}>点击登录</View>
      }

    
    </View>

  )
}
